/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: DynamicFragment
 * Author: Gxjkz
 * Date: 2021/7/14 13:38
 * Description: 个人动态
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Fragment;


import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseFragment;
import com.niuxiaofa.newlaw.Base.RefreshInterface;
import com.niuxiaofa.newlaw.Bean.ByUserBean;
import com.niuxiaofa.newlaw.Network.MePresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.adapter.DynamicAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @ClassName: DynamicFragment
 * @Description: java类作用描述
 * @Author: Gxjkz
 * @Date: 2021/7/14 13:38
 */
public class DynamicFragment extends BaseFragment implements MePresenter.interface_byUser, RefreshInterface.Refresh {

    int currentIndex = 1;


    DynamicAdapter dynamicAdapter;

    List<ByUserBean.DataDTO> dataDTOList = new ArrayList<>();

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;


    @Override
    protected int getLayoutId() {
        return R.layout.view_recyclerview;
    }

    @Override
    public void initData() {
        refreshinterface = new RefreshInterface(this);

        MePresenter.byUser(currentIndex,this);

        dynamicAdapter = new DynamicAdapter(dataDTOList, new DynamicAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });

        RecyclerViewHelp.setRecycler(recyclerview,10).setAdapter(dynamicAdapter);

        Map map = new HashMap();
        map.put("content", "321312");


//        MePresenter. community(map, new MePresenter.interface_community() {
//            @Override
//            public void getResponse(BaseBean u) {
//
//            }
//        });


    }

    @Override
    public void getResponse(ByUserBean u) {
        if (u.getCode() == 1) {

            if (refreshLayout != null) {
                refreshLayout.finishRefresh();
                refreshLayout.finishLoadMore();
            }
            if (currentIndex==1){
                dataDTOList.clear();
            }
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dataDTOList.addAll(u.getData());
            dynamicAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void refresh() {
        currentIndex = 1;
        MePresenter.byUser(currentIndex,this);
    }

    @Override
    public void loadmore() {
        currentIndex++;
        MePresenter.byUser(currentIndex,this);
    }
}